package com.cysyz.web.modules.base.support.filter.page;

import com.cysyz.web.modules.base.support.SysConstants;
import com.cysyz.web.modules.base.user.domain.SysUser;
import com.cysyz.web.modules.base.user.service.SysUserService;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 *
 */
public class PageParameterSetFilter implements Filter {

	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		
	}

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		HttpServletRequest req=(HttpServletRequest)request;

        String start = req.getParameter("start");
        String length = req.getParameter("length");

        if (start != null && length != null) {
            int startN = Integer.parseInt(start);
            int lengthN = Integer.parseInt(length);
            Integer page = startN/lengthN+1;
            Integer pageSize = lengthN;
            req.setAttribute("page", page);

            req.setAttribute("pageSize", pageSize);
        }

    }
}
